home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2404 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: calvados.inria.fr!cluet
  2. From: Sophie.Cluet@inria.fr (Sophie Cluet)
  3. Newsgroups: comp.lang.c++
  4. Subject: storing address of member functions, HELP!
  5. Date: 17 Jan 1996 17:28:04 GMT
  6. Organization: INRIA
  7. Sender: cluet@calvados.inria.fr (Sophie Cluet)
  8. Distribution: world
  9. Message-ID: <4djbj4$5nu@news-rocq.inria.fr>
  10. NNTP-Posting-Host: calvados.inria.fr
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset=iso-8859-1
  13. Content-Transfer-Encoding: 8bit
  14.  
  15. Hello,
  16.  
  17. I have a graph whose nodes represent operations and 
  18. whose edges indicate the operations parameters.
  19. Each operation stores the address of its evaluation 
  20. function which is invoked through a function called
  21. "evaluate" which simply evaluate the operation parameters
  22. and invoke the code.
  23.  
  24. For instance, I have:
  25.   Class nary_op 
  26.     {...
  27.      op ** parameters;      // the edges
  28.      int parameters_nb;
  29.      ...
  30.      int evaluate();    // evaluate the parameters and invoke
  31.                         // the below stored function (code)
  32.      int (nary_op::*code)();  // address of the evaluation function
  33.      ...
  34.      int build_list(); // one such evaluation fonction 
  35.      int and();        // another evaluation function
  36.      ...}
  37.  
  38. The classes are organised in a hierarchy.
  39. For instance, 
  40.   Class struct_op: public nary_op
  41.     {char ** names;  // added stored information
  42.      ...
  43.      int build_struct();  // an evaluation function 
  44.                           // that uses the above names
  45.      ...}
  46.  
  47.       
  48. Now, the problem. The compiler accepts neither of the following 
  49. instructions on a nary_op:
  50.     
  51.      code=&struct_op::build_struct;
  52.   or
  53.      code=(int (nary_op::*)())&struct_op::build_struct;
  54.  
  55. According to the C++ book I have, this assignment
  56. not beeing type-safe is forbidden. I aggree on the
  57. fact that it is not type safe, but I don't know of any
  58. casting that is. 
  59.  
  60. Do you have any idea to help me out?
  61.  
  62. Of course, I do not want to duplicate "code" or the 
  63. "int evaluate()" function. Also, I'd rather have as
  64. little late-binding as possible when evaluating my
  65. operations graph.
  66.  
  67. Thanks in advance,
  68. Sophie.
  69.  
  70.  
  71.  
  72.